package cn.tedu.boot05.controller;

import cn.tedu.boot05.entity.User;
import cn.tedu.boot05.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 作者：HeShaoShuai
 * @Email 邮箱：2569819541@qq.com
 * @Date 日期：2023/5/12 8:33
 * @Package 包名：cn.tedu.boot05.controller
 * @Project 项目名：JavaSE
 * @Version 1.0
 */
@RestController
public class UserController {
	@Autowired
	UserMapper mapper;
	@RequestMapping("/reg")
	public String reg(User user){
		System.out.println("user = " + user);
		//通过用户输入的用户名查询是否存在
		User u = mapper.selectByUsername(user.getUsername());
		//
		if (u!=null){
			return "用户名不存在!";
		}
		//
		mapper.insert(user);
		return "注册成功!<a href='/'>返回首页</a>";
	}
	@RequestMapping("/login")
	public String login(User user){
		System.out.println("user = " + user);
		//
		User u = mapper.selectByUsername(user.getUsername());
		if (u!=null){//
			//
			if (user.getPassword().equals(u.getPassword())){
				return "登录成功！";
			}
			return "密码错误！";
		}
		return "用户名不存在";
	}
}
